package com.practice.springboot.jpa.dao;

import com.practice.springboot.jpa.model.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author sai
 * @create 2020-08-23 5:01
 */
public interface BookDao extends JpaRepository<Book,Long> {

    List<Book> getBooksByAuthorStartingWith(String author) ;

    // GreaterThan 意思为: 大于
    List<Book> getBooksByPriceGreaterThan(Float price) ;

    @Query(value="select * from t_book where id=(select max(id) from t_book)",nativeQuery = true)
    Book getMaxIdBook( ) ;

    @Query("select b from t_book b where b.id>:id and b.author=:author")
    List<Book> getBookByIdAndAuthor(@Param("author") String author,@Param("id") Long id) ;

    @Query("select b from t_book b where b.id<?2 and b.name like %?1%")
    List<Book> getBookByIdnAndName(@Param("name")String name ,@Param("id")Long id ) ;
}
